<?php if (!defined('THINK_PATH')) exit();?><!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>上海泛软科技有限公司-后台登陆</title>
<meta name="robots" content="nofollow" />
<meta name=”viewport” content=”width=device-width, initial-scale=1, maximum-scale=1″>
<link href="/Public/Css/admin-style.css" rel="stylesheet" type="text/css" />
<link href="/Public/Css/bootstrap.css" rel="stylesheet" type="text/css" />
<link href="/Public/Css/bootstrap.min.css" rel="stylesheet" type="text/css" />


<script language="javascript" type="text/javascript" src="/Public/Js/jquery.js"></script>
<script language="javascript" type="text/javascript" src="/Public/Js/admin-common.js"></script>
<script language="javascript" type="text/javascript" src="/Public/Js/bootstrap.min.js"></script>
<!--<script language="javascript" type="text/javascript" src="/Public/Js/bootstrap.js"></script> -->
<script language="javascript" type="text/javascript" src="/Public/Js/rock_customer_list.js"></script>
<script language="javascript" type="text/javascript" src="/Public/Js/demo.js"></script>
<script language="javascript" type="text/javascript" src="/Public/Js/blob.js"></script>
<script language="javascript" type="text/javascript" src="/Public/Js/FileSaver.min.js"></script>
<script language="javascript" type="text/javascript" src="/Public/Js/jquery.base64.js"></script>
<script language="javascript" type="text/javascript" src="/Public/Js/jquery-1.10.2.min.js"></script>
<script language="javascript" type="text/javascript" src="/Public/Js/tableExport.js"></script>
<script language="javascript" type="text/javascript" src="/Public/Js/xlsx.core.min.js"></script>
</head>

<body>

<style>
  #hedaer{
     background:#B9D3EE;
	 padding-left:0px;
	 background-color:rgba(185,211,238,0.15);
	 width:100%;
	 height:120px;
	 border-bottom: 1px solid #ccc;
	 overflow:hidden ;
	 padding-left:10px;
  }
  .select_Sty{
     float:left;
  }
   .select_Sty select {
   width: 150px;
   padding: 1px;
   font-size: 14px;
   border: 1px solid #ccc;
   height: 22px;
   margin-right:20px;
   border-radius:3px
}
.select_Sty input {
   width: 150px;
   padding: 1px;
   font-size: 12px;
   border: 1px solid #ccc;
   height: 22px;
   margin-right:20px;
   border-radius:3px
}
 #content #boder{
    padding-left:10px;
	padding-right:10px;
   
 }
 body{
   background-color:rgba(232,232,232,0.25);
 }
 h5{
   font-size: 10px;
 }
 h4{
   margin-bottom:0px;
   font-size: 14px;
 }
</style>
<div id="background"> 
 
 <div id="hedaer">
   <h4 id="fileName">用户管理</h4>
   <div class="select_Sty">
   <h5>省份:</h5>
    <select name="h_province" class="se">
	  <option value ="请选择">请选择</option>
	  <?php if(is_array($province)): $i = 0; $__LIST__ = $province;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$province): $mod = ($i % 2 );++$i;?><option value ="<?php echo ($province['pro']); ?>"><?php echo ($province["pro"]); ?></option><?php endforeach; endif; else: echo "" ;endif; ?>  
    </select>
   </div>	
    <div class="select_Sty">
     <h5>区、县:</h5>
    <select name="h_city" class="se">
	  <option value ="请选择">请选择</option>
	 <?php if(is_array($city)): $i = 0; $__LIST__ = $city;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$city): $mod = ($i % 2 );++$i;?><option value ="<?php echo ($city['city']); ?>"><?php echo ($city["city"]); ?></option><?php endforeach; endif; else: echo "" ;endif; ?> 
    </select>
   </div>
   <div class="select_Sty">
     <h5>医院:</h5>
    <select name="h_name" class="se">
	  <option value ="请选择">请选择</option>
	 <?php if(is_array($hospital)): $i = 0; $__LIST__ = $hospital;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$hospital): $mod = ($i % 2 );++$i;?><option value ="<?php echo ($hospital['name']); ?>"><?php echo ($hospital["name"]); ?></option><?php endforeach; endif; else: echo "" ;endif; ?> 
    </select>
   </div>
   <div class="select_Sty">
     <h5>用户类型:</h5>
    <select name="u_position" class="se">
	  <option value ="请选择">请选择</option>
	 <?php if(is_array($user_style)): $i = 0; $__LIST__ = $user_style;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$user_style): $mod = ($i % 2 );++$i;?><option value ="<?php echo ($user_style['u_sty']); ?>"><?php echo ($user_style["u_sty"]); ?></option><?php endforeach; endif; else: echo "" ;endif; ?> 
    </select>
   </div>
   <div class="select_Sty"> 
     <h5>手机号1:</h5>
	<input type="type" class="user_tel"  name="u_phonenum" id="user_tel" placeholder="请输入用户手机号"></input>
   </div>
   <div class="select_Sty">
     <h5>用户编号:</h5>
	<input type="type" class="user_no" name="u_id" id="user_no" placeholder="请输入用户编号"></input>
  
   </div>
   <div id="search" style="margin-left:60px;margin-top:40px">
    <button type="button"  class="btn btn-primary btn-sm" onclick="search()">查询</button>
   </div>
 </div>   
 <div id="content">
   <div id="boder">
   <div id="items" style="width:80%;float:left;">
     <p>items：<span id="cou"></span></p> 
   </div>
    <div style="width:20%;float:left;text-align:center">
		 <ul style="float:left;font-weight:bold">
		   <li style="float:left;margin:2px"><a href="#" id="u_modify" data-toggle="modal" data-target="#myModal">编辑</a></li>
		   <li style="float:left;margin:2px"><a href="<?php echo U('user_Management_Add');?>" >增加</a></li>
		   <li style="float:left;margin:2px"><a id="user_delete" onclick="user_delete()">删除</a></li>
		   <li  class="listd" style="float:left;margin:2px"><a id="device_Export">导出</a></li>
		 </ul>
     </div>
	<table class="table table-bordered deviceTblae" style="background:white">
	  <thead style="background-color:rgba(232,232,232,0.35)">
		<tr>
		  <th style="text-align:center"><input class="all_choose"  type="checkbox"></input></th>
		  <th style="text-align:left">用户编号</th>
		  <th style="text-align:left">APP用户标识</th>
		  <th style="text-align:left">所属医院</th>
		  <th style="text-align:left">设备类型</th>
		  <th style="text-align:left">用户手机号</th>
		  <th style="text-align:right">用户类型</th>
		  <th style="text-align:right">状态</th>
		</tr>
	  </thead>
	  <tbody id="content_data">
	  </tbody>
	  
	</table>
	 <ul class="pagination" style="float:right;margin:0px">
     </ul>
   </div>
 </div>
</div>

<!-- 修改--模态框 -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">修改用户数据</h4>
            </div>
            <div class="modal-body">
			    <form enctype="multipart/form-data" name="form1" method="post" action="<?php echo U('user_modify_ok');?>" class="form-horizontal" role="form" >
				  <div class="form-group">
				  
					<label  for="" class="col-sm-2 control-label">用户编号</label>
					<div class="col-sm-10">
					  <input required="required" readonly="readonly" style="width:80%" name="user_num" type="text" class="form-control" id="user_num"><?php echo ($d["d_id"]); ?></input>
					</div>
					
				  </div>
				   <div class="form-group">
					<label  for="" class="col-sm-2 control-label">APP用户标识</label> 
					<div class="col-sm-10">
					  <input required="required" style="width:80%" name="app_user"  type="text" class="form-control" id="app_user" >
					</div>
				  </div>
				   <div class="form-group">
					<label  for="" class="col-sm-2 control-label">所属医院</label>
					<div class="col-sm-10">
					  <input required="required" style="width:80%" name="u_hospital"  type="text" class="form-control" id="u_hospital">
					</div>
				  </div>
				   <div class="form-group">
					<label  for="" class="col-sm-2 control-label">设备类型</label>
					<div class="col-sm-10" id="dev_tihuan">
					   <select style="width:80%" name="u_device_style" id="u_device_style">
					    <option>体温计</option>
					  </select> 
                      <input  style="width:80%;display:none" name="tihuan" id="tihuan" readonly="readonly"   type="text"></input>			  
					 </div>
				  </div>               
				   <div class="form-group">
					<label  for="" class="col-sm-2 control-label">手机号</label>
					<div class="col-sm-10">
					  <input required="required" style="width:80%" name="u_number"  type="text" class="form-control" id="u_number" >
					</div>
				  </div>
				   <div class="form-group">
					<label  for="" class="col-sm-2 control-label">用户类型</label>
					<div class="col-sm-10">
					  <select style="width:80%" name="u_pos" id="u_pos">
					    <option>激活</option>
					  </select>
					  <!-- <input required="required" style="width:80%" name="u_pos" type="text" class="form-control" id="u_pos" > -->
					</div>
				  </div>
				   <div class="form-group">   
					<label  for="" class="col-sm-2 control-label">状态</label>
					<div class="col-sm-10">
					   <select style="width:80%" name="u_status" id="u_status">
					    <option>激活</option>
						<option>未激活</option>
					  </select>
						
					</div>
				  </div>
				  <input style="display:none" name="biaoshi_u_id" id="biaoshi_u_id"></input>
				  <input style="display:none" name="biaoshi_h_id" id="biaoshi_h_id"></input>
				  <input style="display:none" name="biaoshi_d_id" id="biaoshi_d_id"></input>
				  <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="submit"  class="btn btn-primary">提交</button>
                  </div>
				</form>
			</div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
<script>
//test
  init_Data("no",0);
  var userFlag = 0;
  localStorage.userString = "no";
  function init_Data(string,page){
    $.ajax({
  	    url: '/javajy/index.php/Admin/Wenlian/user_Data',
  	    type: 'POST',
 	    dataType: 'JSON',//here
		data:{
		   str:string,
		   pagenum:page
		 },
 	     success: function(obj){
		 data = obj.data;
		 localStorage.sumCount = obj.count;
		 
		 if(localStorage.sumCount != userFlag){
		   userFenYe();
		   userFlag = localStorage.sumCount;
		 }
		  var html='';
		  for(var i = 0; i <data.length; i++){
		     html+=
			 '<tr>'
			  +'<td style="text-align:center" ><input u_id="'+data[i]["u_id"]+'" d_id= "'+data[i]["d_id"]+'" h_id= "'+data[i]["h_id"]+'" class="choose" type="checkbox"></input></td>'
			  +'<td style="text-align:left">'+data[i]["u_id"]+'</td>'
			  +'<td style="text-align:left">'+data[i]["u_APP"]+'</td>'
			  +'<td style="text-align:left">'+data[i]["h_name"]+'</td>'
			  +'<td style="text-align:left">'+data[i]["d_style"]+'</td>'
			  +'<td style="text-align:left">'+data[i]["u_phonenum"]+'</td>'
			  +'<td style="text-align:right">'+data[i]["u_position"]+'</td>'
			  +'<td style="text-align:right">'+data[i]["u_status"]+'</td>'
			+'</tr>'
		  }
          $("#content_data").html(html);
		  $("#cou").html(localStorage.sumCount);
		  //单选
		  $(".choose").click(function(){
		   var u_id = $(this).attr("u_id").substr(1);
		   var all_choose = $(".all_choose").is(':checked');
		   if(all_choose){
		  	  $(".all_choose").prop('checked',false);
			 }
		  });
		 }
	   });
  }
  //用户分页数据
  function userFenYe(){//pagination
   var htmlfen = '';
   if(localStorage.sumCount>=1){   
	htmlfen +='<li class="active fen" page="1"><a href="#">首页</a></li>'
    var pages=Math.ceil(localStorage.sumCount/20);
    for (var i =1; i <= pages;i++){
        htmlfen += '<li class="fen" page='+i+'><a href="#">'+i+'</a></li>'
    }
	var pageEnd = pages+1;
        htmlfen += ' <li class="fen" page='+pages+'><a href="#">末页</a></li>'
    }
	$(".pagination").html(htmlfen);
		$(".fen").each(function(){
		$(this).on("click",function(){
			var applipage=$(this).attr("page");
			
			//$(this).attr("class","active");
			init_Data(localStorage.userString,applipage);
		});
	  
	});
  }
   $(".pagination").on("click","li",function(){
    //分页样式
	 $("li").attr("class","");
	 $(this).attr("class","active");
   })
  //查找
  function search(){//user_no
    var arr = {};
   var user_tel = $(".user_tel").val();
   if(user_tel != ''){
     var name = $(".user_tel").attr("name");
	 var name1 = name.substr(0,1);
	 name = name1+"."+name;
	 arr[name] = user_tel; 
   }
   
   var user_no = $(".user_no").val();
   user_no = user_no.substring(1,user_no.length);
   debugger;
   if(user_no != ''){
     var name = $(".user_no").attr("name");
	 var name1 = name.substr(0,1);
	 name = name1+"."+name;
	 arr[name] = user_no; 
   }
   
    $(".se").each(function(){
	   var value = $(this).val();
	   if($(this).val()!="请选择"){
	      if($(this).attr("name") =="u_id" ){
		    value = value.substr(1);
		  }
		 var name = $(this).attr("name");
		 var name1 = name.substr(0,1);
		 name = name1+"."+name;
		 arr[name] = value; 
	   }
	});
	var string = JSON.stringify(arr);//将数组转为json
	init_Data(string,1);
	localStorage.userString = string;
  }
   //全选
  $(".all_choose").click(function(){
     var flag = $(this).is(':checked');
	 if(flag){
	      $(".choose").each(function(){
		  $(this).prop('checked',true);
	    })
	 }else{
	    $(".choose").each(function(){
		  $(this).prop('checked',false);
	    })
	 }
  })
  //修改
  $("#u_modify").click(function (){
    var len = $("input[type='checkbox']:checked").length;//修改数据的个数
	 if(len == 0){
	   alert("请选择修改的用户");
	   return false;
	 }else if(len!=1){
	   alert("每次只能修改一个用户数据");
	   return false;
	 }
	 var u_id = '';
	 var h_id = '';
	 var d_id = '';
	$(".choose").each(function(){
        var f_this = $(this).is(':checked');		
        if(f_this){
		   u_id = $(this).attr("u_id").substr(1);
		   d_id = $(this).attr("d_id");
		   h_id = $(this).attr("h_id");
		}		
	 })
	 $.ajax({
  	    url: '/javajy/index.php/Admin/Wenlian/modify_user',
  	    type: 'POST',
 	    dataType: 'JSON',//here
		data:{
		   user_id:u_id,
		   dev_id:d_id,
		   hos_id:h_id
		 },
 	     success: function(data){ 
		 var s =data[3];
		 debugger;
          //用户类型
		   var html1=''
		   for(var i=0; i<s.length;i++){
		     html1+=
			  '<option value="'+s[i]["u_position"]+'">'+s[i]["u_position"]+'</option>'
		   }
		  $("#u_pos").html(html1);
		  
		   $("#user_num").val("U"+data[0][0]["u_id"]);
		   $("#app_user").val(data[0][0]["u_APP"]);
		   $("#u_hospital").val(data[1][0]["h_name"]);
		   $("#u_device_style").val(data[2][0]["d_style"]);
		   $("#u_number").val(data[0][0]["u_phonenum"]);
		   $("#u_pos").val(data[0][0]["u_position"]);
		   $("#u_status").val(data[0][0]["u_status"]);
		   //$("#all_ID").val(data[0][0]["d_id"]+","+data[1][0]["u_id"]+","+data[2][0]["h_id"]);
		   if(data[2][0]["d_style"] == "暂无"){
		      $("#u_device_style").css("display","none");
			  $("#tihuan").css("display","block");
			  $("#tihuan").val("该用户暂时没有设备");
			  $("#biaoshi_u_id").val(data[0][0]["u_id"]);
			  $("#biaoshi_d_id").val("暂无");
			  $("#biaoshi_h_id").val(data[1][0]["h_id"]);
		   }else{
		      $("#u_device_style").css("display","block");
			  $("#tihuan").css("display","none");
			  $("#biaoshi_u_id").val(data[0][0]["u_id"]);
			  $("#biaoshi_d_id").val(data[2][0]["d_id"]);
			  $("#biaoshi_h_id").val(data[1][0]["h_id"]);
		   }
		 }
	   });
  })
  //用户删除
  function user_delete(){
    var len = $("input[type='checkbox']:checked").length;//删除用户的个数
	if(len == 0){
	   alert("请选择需要删除的用户");
	}else{
	  var u_arr = new Array();//
	  $(".choose").each(function(){
        var f_this = $(this).is(':checked');		
        if(f_this){
			u_arr.push($(this).attr("u_id").substr(1));
	     }		
	   })
      var string1 = JSON.stringify(u_arr);//将数组转为json
	  $.ajax({
  	    url: '/javajy/index.php/Admin/Wenlian/user_delete',
  	    type: 'POST',
 	    dataType: 'JSON',//here
		data:{
		   destr:string1
		 },
 	     success: function(data){
		  alert(data);
		  location.reload(true);                                     
		 }
	   });
     }
  }
  //获取日期与时间
 function getNowFormatDate() {
    var date = new Date();
    var seperator1 = "-";
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
	var hours = date.getHours(); //获取当前小时数(0-23)
    var min =  date.getMinutes(); //获取当前分钟数(0-59)
    var second = date.getSeconds(); //获取当前秒数(0-59)
	
    if (month >= 1 && month <= 9) {
         month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
	if(hours >=0 && hours <= 9){
	   hours = "0" + hours;
	}
	if(min >=0 && min <= 9){
	   min = "0" + min;
	}
	if(second >=0 && second <= 9){
	   second = "0" + second;
	}
    var currentdate = year + seperator1 + month + seperator1 + strDate +" "+hours +"时" + min+"分" + second+"秒";
    return currentdate;
 } 
 //导出exce
 var exportData = document.getElementById("device_Export");
 exportData.onclick = function(){
    //$(".deviceTblae").tableExport({ type: 'excel', separator: ';', escape: 'false' });
	var fName = $("#fileName").html();
	var currentTime =  getNowFormatDate();
	fName = fName+'_'+currentTime;
	$(".deviceTblae").tableExport({ type: 'excel', separator: ',', escape: 'false',fileName:fName });
 }
</script>

</body>
</html>